package cn.iocoder.yudao.module.erp.dal.mysql.contractpaymentplan.contractpaymentplandetail;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.contractpaymentplan.vo.contractpaymentplandetail.ContractPaymentPlanDetailPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.contractpaymentplan.contractpaymentplandetail.ContractPaymentPlanDetailDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 合同付款计划明细 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ContractPaymentPlanDetailMapper extends BaseMapperX<ContractPaymentPlanDetailDO> {

    default PageResult<ContractPaymentPlanDetailDO> selectPage(ContractPaymentPlanDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ContractPaymentPlanDetailDO>()
                .eqIfPresent(ContractPaymentPlanDetailDO::getPaymentPlanId, reqVO.getPaymentPlanId())
                .eqIfPresent(ContractPaymentPlanDetailDO::getPlanNo, reqVO.getPlanNo())
                .eqIfPresent(ContractPaymentPlanDetailDO::getPeriod, reqVO.getPeriod())
                .betweenIfPresent(ContractPaymentPlanDetailDO::getPlanDate, reqVO.getPlanDate())
                .eqIfPresent(ContractPaymentPlanDetailDO::getPaymentType, reqVO.getPaymentType())
                .eqIfPresent(ContractPaymentPlanDetailDO::getPlanPaymentRatio, reqVO.getPlanPaymentRatio())
                .eqIfPresent(ContractPaymentPlanDetailDO::getPlanPaymentAmount, reqVO.getPlanPaymentAmount())
                .eqIfPresent(ContractPaymentPlanDetailDO::getActualPaymentStatus, reqVO.getActualPaymentStatus())
                .eqIfPresent(ContractPaymentPlanDetailDO::getActualAmount, reqVO.getActualAmount())
                .betweenIfPresent(ContractPaymentPlanDetailDO::getActualDate, reqVO.getActualDate())
                .betweenIfPresent(ContractPaymentPlanDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ContractPaymentPlanDetailDO::getId));
    }

    default void deleteByPaymentPlanId(Long paymentPlanId){
        LambdaQueryWrapperX<ContractPaymentPlanDetailDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eq(ContractPaymentPlanDetailDO::getPaymentPlanId, paymentPlanId);
        this.delete(queryWrapperX);
    }

    default void deleteByPaymentPlanIds(List<Long> paymentPlanIds){
        LambdaQueryWrapperX<ContractPaymentPlanDetailDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.in(ContractPaymentPlanDetailDO::getPaymentPlanId, paymentPlanIds);
        this.delete(queryWrapperX);
    }

    default List<ContractPaymentPlanDetailDO> selectByPaymentPlanId(Long paymentPlanId){
        return this.selectList(ContractPaymentPlanDetailDO::getPaymentPlanId, paymentPlanId);
    }
}